package com.example.carrierapp.util;

import android.graphics.Color;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;

/**
 *设置富文本
 */
public class SpannableUtils {

    static SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();

    public static SpannableStringBuilder showDiffColor(String str, int start, int end) {
        if (spannableStringBuilder.length() > 0) {
            spannableStringBuilder.clear();
        }
        spannableStringBuilder.append(str);
        spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#427fed")), start,
                end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        return spannableStringBuilder;
    }

    public static SpannableStringBuilder showDiffSize(String str, int start, int end, int size) {
        if (spannableStringBuilder.length() > 0) {
            spannableStringBuilder.clear();
        }
        spannableStringBuilder.append(str);
        spannableStringBuilder.setSpan(new AbsoluteSizeSpan(size), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        return spannableStringBuilder;
    }
}
